<template>
  <div class="search-box">
    <Header />
    <div class="main">
      <div class="content">
        <div class="search">
          <el-input placeholder="请输入想搜索的作品关键字..." :prefix-icon="Search" />
          <div class="tabs">
            <el-tabs v-model="activeName">
              <el-tab-pane label="全部" name="first" />
              <el-tab-pane label="作者" name="second" />
            </el-tabs>
          </div>

          <div
            class="pc-filter-type"
            :class="{ 'is-hidden': !isExpanded, 'is-expanded': isExpanded }"
          >
            <div class="inner">
              <div class="tit">
                <span>选择筛选条件</span>
                <el-button :icon="Search" text @click="toggleExpand">
                  <span>进阶筛选</span>
                </el-button>
              </div>
              <div class="tag-btn">
                <el-button round>日常温馨</el-button>
                <el-button round>西幻</el-button>
                <el-button round>奇幻</el-button>
                <el-button round>未来科幻</el-button>
                <el-button round>重生穿越</el-button>
                <el-button round>玄幻仙侠武侠</el-button>
                <el-button round>犯罪悬疑推理</el-button>
                <el-button round>恐怖惊悚灵异</el-button>
                <el-button round>青春校园</el-button>
                <el-button round>现代社会</el-button>
                <el-button round>古代历史</el-button>
                <el-button round>近代民国</el-button>
                <el-button round>其他架空世界观</el-button>
              </div>
              <div class="select-line">
                <div class="line">
                  <span>进度</span>
                  <div class="line-select">
                    <el-button>连载中</el-button>
                    <el-button>已完结</el-button>
                  </div>
                </div>
                <div class="line">
                  <span>字数</span>
                  <div class="line-select">
                    <el-button>5万以下</el-button>
                    <el-button>5-10万</el-button>
                    <el-button>10-30万</el-button>
                    <el-button>30-50万</el-button>
                    <el-button>50-100万</el-button>
                    <el-button>100万以上</el-button>
                  </div>
                </div>
                <hr class="divider" />

                <div class="line">
                  <span>分级</span>
                  <div class="line-select">
                    <el-button>一般向</el-button>
                    <el-button>成人向</el-button>
                  </div>
                </div>

                <div class="line">
                  <span>篇幅</span>
                  <div class="line-select">
                    <el-button>短篇</el-button>
                    <el-button>中篇</el-button>
                    <el-button>长篇</el-button>
                    <el-button>大长篇</el-button>
                  </div>
                </div>

                <!-- <div class="line">
                  <span>解鎖</span>
                  <div class="line-select">
                    <el-button>免費</el-button>
                    <el-button>讀角券</el-button>
                    <el-button>付費</el-button>
                    <el-button>訂閱</el-button>
                  </div>
                </div>
                <hr class="divider" />-->

                <!-- <div class="line">
                  <span>類型</span>
                  <div class="line-select">
                    <el-button>簽約作品</el-button>
                    <el-button>創作作品</el-button>
                  </div>
                </div>-->
              </div>
              <div class="submit-box">
                <el-button round>清除</el-button>
                <el-button round>确定筛选</el-button>
              </div>
            </div>
          </div>
          <div class="filter-type">
            <el-button :icon="Search" round @click="handleFilter1">最相关</el-button>
            <el-button :icon="Search" round @click="handleFilter2">筛选</el-button>
          </div>

          <div class="space-between shaixuan-boss">
            <div>
              <el-dropdown trigger="click">
                <span class="el-dropdown-link">
                  最相关
                  <el-icon class="el-icon--right" :size="16">
                    <ArrowDown />
                  </el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item>最相关</el-dropdown-item>
                    <el-dropdown-item>最新更新</el-dropdown-item>
                    <el-dropdown-item>最新上架</el-dropdown-item>
                    <el-dropdown-item>点赞最多</el-dropdown-item>
                    <el-dropdown-item>收藏最多</el-dropdown-item>
                    <el-dropdown-item>浏览最多</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
            <div class="shaixuan-tag">已筛选：奇幻</div>
          </div>

          <div class="search-result">
            <span>还没找到相关的作品</span>
          </div>

          <div class="explore-more">
            <div class="tit">
              <h2>探索更多</h2>
            </div>
            <div class="works-list">
              <div class="work-item" v-for="(item, index) in moreWorks" :key="index">
                <div class="top">
                  <div class="image">
                    <img :src="item.imgUrl" alt />
                    <div class="tag">{{ item.tagName }}</div>
                  </div>
                  <div class="text">
                    <span class="work-tit">{{ item.title }}</span>
                    <span class="work-author">{{ item.author }}</span>
                    <span class="work-info">{{ item.info }}</span>
                  </div>
                </div>
                <div class="bottom">
                  <div class="count">
                    <div>
                      <img class="count-img" src="../assets/images/wujue.png" alt />
                      <span>{{ item.like }}</span>
                    </div>
                    <div>
                      <img class="count-img" src="../assets/images/details.png" alt />
                      <span>{{ item.view }}</span>
                    </div>
                  </div>
                  <div class="zan">
                    <img class="count-img" src="../assets/images/wujue-1.png" alt />
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <van-popup v-model:show="filterDrawer" class="custom-popup" round position="bottom" :style="{ minHeight: '40%'}">
        <!-- <el-drawer v-model="filterDrawer" :show-close="false" :with-header="false" :direction="direction"> -->
        <div class="sort-type" v-show="drawerValue == 1">
          <el-button>最相关</el-button>
          <el-button>最新更新</el-button>
          <el-button>最新上架</el-button>
          <el-button>点赞最多</el-button>
          <el-button>收藏最多</el-button>
          <el-button>浏览最多</el-button>
        </div>
        <div class="filter-type2" v-show="drawerValue == 2">
          <div class="classify" @click="toggleExpand">
            <span>分类</span>
            <el-icon>
              <ArrowDownBold />
            </el-icon>
          </div>
          <div
            class="tag-container"
            :class="{ 'is-hidden': !isExpanded, 'is-expanded': isExpanded }"
          >
            <div class="tag-btn">
              <el-button v-for="(item,index) in typeBosList" :key="index" round>{{item.text}}</el-button>
            </div>
          </div>
          <div class="line">
            <span>进度</span>
            <div class="line-select">
              <el-button>连载中</el-button>
              <el-button>已完结</el-button>
            </div>
          </div>
          <div class="line">
            <span>字数</span>
            <div class="line-select">
              <el-button>5万以下</el-button>
              <el-button>5-10万</el-button>
              <el-button>10-30万</el-button>
              <el-button>30-50万</el-button>
              <el-button>50-100万</el-button>
              <el-button>100万以上</el-button>
            </div>
          </div>
          <div class="line">
            <span>分级</span>
            <div class="line-select">
              <el-button text>一般向</el-button>
              <el-button>成人向</el-button>
            </div>
          </div>
          <div class="line">
            <span>篇幅</span>
            <div class="line-select">
              <el-button>短篇</el-button>
              <el-button>中篇</el-button>
              <el-button>长篇</el-button>
              <el-button>大长篇</el-button>
            </div>
          </div>
        </div>
        <!-- </el-drawer> -->
      </van-popup>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import Header from "../components/Header.vue";
import { Search, ArrowDownBold } from "@element-plus/icons-vue";
import {
  ArrowLeftBold,
  Setting,
  EditPen,
  ArrowDown,
  Sort,
  MoreFilled,
  View,
  Tickets
} from "@element-plus/icons-vue";
const activeName = ref("first");

const filterDrawer = ref(false);
const drawerValue = ref(1);
const direction = ref("btt");

const handleFilter1 = () => {
  drawerValue.value = 1;
  filterDrawer.value = true;
};

const handleFilter2 = () => {
  drawerValue.value = 2;
  filterDrawer.value = true;
};

const isExpanded = ref(false);
const toggleExpand = () => {
  isExpanded.value = !isExpanded.value;
};

// 探索更多列表数据
const moreWorks = ref([
  {
    imgUrl: new URL("../assets/images/book3.jpg", import.meta.url),
    tagName: "完結",
    title: "旅行者",
    author: "Div",
    info:
      "★ 出版情報：下集 2023/11/29正式開賣！ 《旅行者(下)》／定價：300元 更多書籍资讯：https://reurl.cc/x6V855•《地獄》系列暢銷作家Div嶄新代表作，冒險系網遊小说突入最終章！•收錄《旅行者》第二部全文、單行本獨家收錄感動番外篇。•首刷限定：鸚鵡洲特繪雙主角Q版可愛杯墊！一共兩款．隨機贈送（※首刷售完即無贈品）",
    like: "0",
    view: "10"
  },
  {
    imgUrl: new URL("../assets/images/book3.jpg", import.meta.url),
    tagName: "完結",
    title: "旅行者",
    author: "Div",
    info:
      "★ 出版情報：下集 2023/11/29正式開賣！ 《旅行者(下)》／定價：300元 更多書籍资讯：https://reurl.cc/x6V855•《地獄》系列暢銷作家Div嶄新代表作，冒險系網遊小说突入最終章！•收錄《旅行者》第二部全文、單行本獨家收錄感動番外篇。•首刷限定：鸚鵡洲特繪雙主角Q版可愛杯墊！一共兩款．隨機贈送（※首刷售完即無贈品）",
    like: "0",
    view: "10"
  }
]);

const typeBosList = ref([
  {
    text: "日常温馨",
    src: "",
    href: "/search"
  },
  {
    text: "西幻",
    src: "",
    href: "/search"
  },
  {
    text: "奇幻",
    src: "",
    href: "/search"
  },
  {
    text: "未来科幻",
    src: "",
    href: "/search"
  },
  {
    text: "重生穿越",
    src: "",
    href: "/search"
  },
  {
    text: "玄幻仙侠武侠",
    src: "",
    href: "/search"
  },
  {
    text: "犯罪悬疑推理",
    src: "",
    href: "/search"
  },
  {
    text: "恐怖惊悚灵异",
    src: "",
    href: "/search"
  },
  {
    text: "青春校园",
    src: "",
    href: "/search"
  },
  {
    text: "现代社会",
    src: "",
    href: "/search"
  },
  {
    text: "古代历史",
    src: "",
    href: "/search"
  },
  {
    text: "近代民国",
    src: "",
    href: "/search"
  },
  {
    text: "其他架空世界观",
    src: "",
    href: "/search"
  }
]);
</script>


<style lang="scss" scoped>
.count-img {
  width: 15px;
}

.shaixuan-boss {
  margin-top: 10px;
}

.shaixuan-tag {
  color: #fa715d;
}

.main {
  .content {
    padding-left: 1rem;
    padding-right: 1rem;
    margin: 0px auto;
    max-width: 61.5rem;

    :deep(.el-input__wrapper) {
      margin: 1rem 0px 0px;
      min-width: 0px;
      display: flex;
      width: 100%;
      height: 3rem;
      border-radius: 0.25rem;
      border-width: 1px;
      border-style: solid;
      border-color: #f7fafc;
      box-sizing: border-box;
      -webkit-box-align: center;
      align-items: center;
      background-color: #f7fafc;
    }

    :deep(.el-tabs__nav-wrap:after) {
      display: none;
    }

    :deep(.el-tabs__item) {
      font-size: 0.875rem;
      font-weight: 500;
      line-height: 1.5;
      letter-spacing: 0.05em;
      flex-shrink: 0;
      white-space: nowrap;
      position: relative;
      display: flex;
      -webkit-box-pack: center;
      justify-content: center;
      -webkit-box-align: center;
      align-items: center;
      min-width: 6rem;
      padding-left: 1rem;
      padding-right: 1rem;
      color: #2d3748;
    }

    :deep(.el-tabs__item.is-active) {
      color: #fa715d;
    }

    :deep(.el-tabs__active-bar) {
      background-color: #fa715d;
    }

    :deep(.el-button) {
      margin: 0;
      margin: 0.25rem 0px;
      height: 2.25rem;
      padding: 0.5rem 1rem;
    }

    .tabs {
      margin-top: 0.5rem;
    }

    .search-result {
      font-size: 1rem;
      font-weight: 400;
      line-height: 1.5;
      letter-spacing: 0.05em;
      padding: 0.5rem 1rem;
      color: #718096;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 2rem;
      margin-bottom: 2rem;
    }

    .explore-more {
      .tit {
        margin-bottom: 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 3rem;
        gap: 1rem;

        h2 {
          font-size: 1rem;
          font-weight: 400;
          line-height: 1.5;
          letter-spacing: 0.05em;
          color: #2d3748;
        }
      }
    }
  }

  :deep(.el-drawer) {
    margin: 0px auto;
    min-width: 0px;
    display: flex;
    flex-flow: column;
    max-height: calc(100% - 4rem);
    width: 100%;
    max-width: 32rem;
    border-top-right-radius: 0.5rem;
    border-top-left-radius: 0.5rem;
    min-height: 50dvh;
  }

  .sort-type {
    button {
      margin: 0px;
      border: 0px;
      font-size: 0.875rem;
      font-weight: 500;
      line-height: 1.5;
      letter-spacing: 0.05em;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 0.5rem;
      padding: 0rem 1rem;
      color: #2d3748;
      width: 100%;
      height: 3rem;

      &:not(:last-child) {
        border-bottom-width: 1px;
        border-bottom-style: solid;
        border-bottom-color: #edf2f7;
      }
    }
  }

  .filter-type2 {
    .classify {
      display: grid;
      gap: 1rem;
      grid-template-columns: 1fr auto;
      height: 3rem;
      -webkit-box-align: center;
      align-items: center;
    }

    .tag-container {
      overflow: hidden;

      .tag-btn {
        display: flex;
        flex-flow: row wrap;
        gap: 0.5rem;

        :deep(.el-button) {
          margin: 0.25rem 0px;
          padding: 0.5rem 1rem;
          color: #2d3748;
          border-width: 0.0625rem;
          border-style: solid;
          border-color: #cbd5e0;
          font-size: 0.875rem;
          font-weight: 400;
          line-height: 2;
          letter-spacing: 0.05em;
          display: flex;
          justify-content: center;
          align-items: center;
          gap: 0.5rem;
          height: 2.25rem;
          width: auto;
          max-width: 100%;
          border-radius: 36px;
        }
      }
    }

    .line {
      display: grid;
      grid-gap: 1rem;
      grid-template-columns: auto 1fr;
      align-items: center;
      border-bottom: 1px solid #edf2f7;

      span {
        font-size: 0.875rem;
        font-weight: 500;
        line-height: 1.5;
        letter-spacing: 0.05em;
        color: #2d3748;
        padding-right: 1rem;
        color: #718096;
        min-width: 3.5rem;
      }

      .line-select {
        display: flex;
        gap: 0.5rem;

        :deep(.el-button) {
          margin: 0;
          border: 0;
          border-radius: 4px;
          font-size: 0.875rem;
          font-weight: 500;
          line-height: 1.5;
          letter-spacing: 0.05em;
          gap: 0.5rem;
          height: 3rem;
          color: #2d3748;

          &:hover {
            background: none;
            color: #ff8674;
          }
        }
      }
    }
  }

  :deep(.el-button:hover) {
    background: none;
    color: #fa715d;
  }
}

.pc-filter-type {
  padding: 1rem;
  background-color: #f7fafc;
  display: none;
  flex-direction: column;

  .inner {
    flex: 1 1 auto;
    overflow: hidden;

    .tit {
      display: flex;
      height: 3rem;
      -webkit-box-pack: justify;
      justify-content: space-between;
      -webkit-box-align: center;
      align-items: center;

      span {
        font-size: 0.875rem;
        font-weight: 500;
        line-height: 1.5;
        letter-spacing: 0.05em;
        color: #2d3748;
      }

      i {
        font-size: 1.5rem;
      }
    }

    .tag-btn {
      display: flex;
      flex-flow: wrap;
      gap: 0.5rem;
    }
  }

  &.is-hidden {
    height: 8.25rem;
  }

  &.is-expanded {
    height: auto;
  }
}

.filter-type {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);

  :deep(.el-button) {
    font-size: 0.875rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    height: 2.25rem;
    width: auto;
  }
}

.select-line {
  display: grid;
  gap: 0rem;
  grid-template-columns: repeat(2, 1fr);

  .line {
    display: grid;
    gap: 1rem;
    grid-template-columns: auto 1fr;
    -webkit-box-align: center;
    align-items: center;

    span {
      font-size: 0.875rem;
      font-weight: 500;
      line-height: 1.5;
      letter-spacing: 0.05em;
      padding-right: 1rem;
      color: #718096;
      min-width: 3.5rem;
    }

    .line-select {
      display: flex;
      gap: 0.5rem;
    }
  }
}

.works-list {
  display: grid;
  gap: 2rem;
  grid-template-columns: repeat(1, 1fr);

  .work-item {
    display: grid;

    .top {
      display: flex;
      gap: 1rem;
      margin-bottom: 0.5rem;

      .image {
        display: block;
        flex: 0 0 auto;
        position: relative;
        box-shadow: rgba(203, 213, 224, 0.3) 0px 0px 2rem 0px;
        aspect-ratio: 7 / 10;
        width: 7rem;
        clip-path: inset(0px round 0.25rem);

        img {
          display: block;
          width: 100%;
        }

        .tag {
          font-size: 0.625rem;
          font-weight: 600;
          line-height: 1.625;
          letter-spacing: 0.05em;
          padding-left: 0.5rem;
          padding-right: 0.5rem;
          color: #ffffff;
          display: flex;
          position: absolute;
          top: 0.375rem;
          right: 0.375rem;
          background-color: rgba(113, 128, 150, 0.5);
          border-radius: 50rem;
        }
      }

      .text {
        display: flex;
        flex: 1 1 0%;
        flex-direction: column;
        min-height: 10.125rem;
        gap: 0.5rem;

        .work-tit {
          font-size: 0.875rem;
          font-weight: 500;
          line-height: 1.5;
          letter-spacing: 0.05em;
          color: #2d3748;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          word-break: break-all;
          overflow: hidden;
        }

        .work-author {
          font-size: 0.75rem;
          font-weight: 400;
          line-height: 1.625;
          letter-spacing: 0.05em;
          color: #2d3748;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          word-break: break-all;
          overflow: hidden;
        }

        .work-info {
          margin: 0.5rem 0px 0px;
          min-width: 0px;
          font-size: 0.75rem;
          font-weight: 400;
          line-height: 1.625;
          letter-spacing: 0.05em;
          color: #92aaca;
          display: -webkit-box;
          -webkit-line-clamp: 4;
          -webkit-box-orient: vertical;
          word-break: break-all;
          overflow: hidden;
        }
      }
    }

    .bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .count {
        display: flex;
        align-items: center;
        gap: 0.5rem;

        div {
          font-size: 0.75rem;
          font-weight: 400;
          line-height: 1.625;
          letter-spacing: 0.05em;
          color: #718096;
          display: flex;
          align-items: center;
          gap: 0.5rem;
        }
      }

      .zan {
        :deep(.el-button) {
          height: 3rem;
          width: 3rem;
          font-size: 1.5rem;
          border: none;
          color: #fa715d;
          background-color: #f7fafc;
        }
      }
    }
  }
}

.is-hidden {
  height: 3rem;
}

.is-expanded {
  height: auto;
}

.divider {
  min-width: 0px;
  border-width: 0px 0px 1px;
  border-top-style: initial;
  border-right-style: initial;
  border-left-style: initial;
  border-color: initial;
  border-image: initial;
  border-bottom-style: solid;
  width: 100%;
  height: 1px;
  margin: 0rem;
  color: #edf2f7;
  grid-column: 1 / 3;
}
/* 在对应的wxss文件中 */
.custom-popup {
  padding: 16px; /* 设置内边距 */
}
@media screen and (min-width: 640px) {
  .works-list {
    grid-template-columns: repeat(1, 1fr);
  }

  .filter-type {
    display: grid;
  }

  .pc-filter-type {
    display: none;
  }
}

@media screen and (min-width: 768px) {
  .works-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .filter-type {
    display: none;
  }

  .pc-filter-type {
    display: flex;
  }
}

@media screen and (min-width: 1024px) {
  .works-list {
    grid-template-columns: repeat(3, 1fr);
  }
}
</style>